package indi.h.targetcall.calls;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import indi.h.targetcall.locks.DataConflictLock;
import indi.h.targetcall.locks.Lock;
import indi.h.targetcall.manager.TManager;

public class SThreadToolCall<T, E extends ExecutorService> extends STCall<T, E> {

	private int defaultTime;
	private TimeUnit defaultTimeType;
	private ReentrantLock rl;

	public SThreadToolCall(TManager<T, E> tManager) {
		// TODO Auto-generated constructor stub
		this(tManager, new DataConflictLock<>());
	}

	public SThreadToolCall(TManager<T, E> tManager, Lock<T> lock) {
		// TODO Auto-generated constructor stub
		this(tManager, lock, 1, TimeUnit.SECONDS);
	}

	public SThreadToolCall(TManager<T, E> tManager, Lock<T> lock, int defaultTime, TimeUnit defaultTimeType) {
		// TODO Auto-generated constructor stub
		super(tManager, lock);
		this.defaultTime = defaultTime;
		this.defaultTimeType = defaultTimeType;
		this.rl = new ReentrantLock();
	}

	/*
	 * @Override public void reset(T id, E es,EndOperation<E> end) throws
	 * Exception { // TODO Auto-generated method stub this.lock.lock(id); try {
	 * boolean isNow = o.length > 0 ? (boolean) o[0] : false; SExecutorService
	 * target = (SThreadToolCall<T, E>.SExecutorService) this.tManager.take(id);
	 * if (isNow && target != null) target.shutdownNow(); else if (target !=
	 * null) { new Thread() { public void run() { target.shutdown(); };
	 * }.start(); } ExecutorService e = o.length > 2 ? new SExecutorService(es,
	 * (int) o[1], (TimeUnit) o[2]) : new SExecutorService(es, this.defaultTime,
	 * defaultTimeType); this.tManager.put(id, (E) e); } finally {
	 * this.lock.unLock(id); } }
	 */

	/*
	 * @Override public E spitE(T id) throws Exception { // TODO Auto-generated
	 * method stub return this.tManager.take(id); }
	 */

	/*
	 * @Override public void packing(T id, Task<E> t) throws Exception { // TODO
	 * Auto-generated method stub t.exec(this.tManager.get(id)); }
	 */
	
	/*
	 * private class SExecutorService implements ExecutorService { private
	 * ExecutorService e; private int time; private TimeUnit timeType;
	 * 
	 * public SExecutorService(ExecutorService e, int time, TimeUnit timeType) {
	 * // TODO Auto-generated constructor stub this.e = e; this.time = time;
	 * this.timeType = timeType; }
	 * 
	 * public int getDefaultTime() { return this.time; }
	 * 
	 * public TimeUnit getDefaultTimeType() { return this.timeType; }
	 * 
	 * @Override public void execute(Runnable command) { // TODO Auto-generated
	 * method stub e.execute(command); }
	 * 
	 * @Override public void shutdown() { // TODO Auto-generated method stub
	 * e.shutdown(); }
	 * 
	 * @Override public List<Runnable> shutdownNow() { // TODO Auto-generated
	 * method stub return e.shutdownNow(); }
	 * 
	 * @Override public boolean isShutdown() { // TODO Auto-generated method
	 * stub return e.isShutdown(); }
	 * 
	 * @Override public boolean isTerminated() { // TODO Auto-generated method
	 * stub return e.isTerminated(); }
	 * 
	 * @Override public boolean awaitTermination(long timeout, TimeUnit unit)
	 * throws InterruptedException { // TODO Auto-generated method stub return
	 * e.awaitTermination(timeout, unit); }
	 * 
	 * @Override public <T> Future<T> submit(Callable<T> task) { // TODO
	 * Auto-generated method stub return e.submit(task); }
	 * 
	 * @Override public <T> Future<T> submit(Runnable task, T result) { // TODO
	 * Auto-generated method stub return e.submit(task, result); }
	 * 
	 * @Override public Future<?> submit(Runnable task) { // TODO Auto-generated
	 * method stub return e.submit(task); }
	 * 
	 * @Override public <T> List<Future<T>> invokeAll(Collection<? extends
	 * Callable<T>> tasks) throws InterruptedException { // TODO Auto-generated
	 * method stub return e.invokeAll(tasks); }
	 * 
	 * @Override public <T> List<Future<T>> invokeAll(Collection<? extends
	 * Callable<T>> tasks, long timeout, TimeUnit unit) throws
	 * InterruptedException { // TODO Auto-generated method stub return
	 * e.invokeAll(tasks, timeout, unit); }
	 * 
	 * @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
	 * throws InterruptedException, ExecutionException { // TODO Auto-generated
	 * method stub return e.invokeAny(tasks); }
	 * 
	 * @Override public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
	 * long timeout, TimeUnit unit) throws InterruptedException,
	 * ExecutionException, TimeoutException { // TODO Auto-generated method stub
	 * return e.invokeAny(tasks, timeout, unit); }
	 * 
	 * }
	 */

}
